#include <vector>

#include "Client.h"

Client::Client() {

}

Client::Client(const Doctor &familyDoctor, const Profession &profession, const Code &code) {
    setFamilyDoctor(familyDoctor);
    setProfession(profession);
    setClientCode(code);
}

Client::~Client() {

}

Doctor *Client::getFamilyDoctor() const {
    return familyDoctor;
}

void Client::setFamilyDoctor(const Doctor &familyDoctor) {
    this->familyDoctor = &familyDoctor;
}

Profession *Client::getProfession() const {
    return profession;
}

void Client::setProfession(const Profession &profession) {
    this->profession = &profession;
}

Code *Client::getClientCode() const {
    return clientCode;
}

void Client::setClientCode(const Code &clientCode) {
    this->clientCode = &clientCode;
}

bool Client::addConsultation(const Consultation &consultation) {
    if (consults.push_back(&consultation))
        return true;
    return false;
}

void Client::printAppointmentHistoricalData(unsigned short deepness = 0) {
    unsigned short appointmentsMadeSize = appointmentsMade.size();

    if (deepness == 0)
        deepness = appointmentsMadeSize;

    for (unsigned int i = 0; i < deepness && i < appointmentsMadeSize; i++) {
        cout << "Appointment " << appointmentsMadeSize - i << ":" << endl;
        cout << appointmentsMade[appointmentsMadeSize - (i + 1)] << endl;
    }

}

string Client::printConsultationHistoricalData(unsigned short deepness = 0) {
    unsigned short consultsSize = consults.size();
    stringstream info;

    if (consultsSize == 0)
        return info.str();

    if (deepness == 0)
        deepness = consultsSize;

    for (unsigned int i = 0; i < deepness && i < consultsSize; i++) {
        info << "Consultation " << consultsSize - i << ":" << endl;
        info << appointmentsMade[consultsSize - (i + 1)] << endl;
    }

    return info.str();
}

void Client::printExistingProfessions() {
    cout << "\nProfessions" << endl;

    for (unsigned int i = 0; i < existentProfessions.size(); i++) {
        cout << i + 1 << ". " << existentProfessions[i] << endl;
    }
}

string Client::printClient(int consults = 0, int appointments = 0) {
    stringstream info;

    info << "Client " << this->getClientCode().printCode() << endl << endl;
    info << this->printPerson() << endl;
    info << "Profession: " << this->getProfession().printProfession();
    info << "Family Doctor:\n" << this->getFamilyDoctor().printDoctor() << endl;

    if (consults != 0) {
        info << endl << "Consultations Historical Data:" << endl <<
                printConsultationHistoricalData(consults) << endl;
    }

    if (appointments != 0)
        printAppointmentHistoricalData(appointments);


}